home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / AppMaker 2.0b3 / Demo AppMaker 1.5 / Demo AppMaker™ / Demo AppMaker™.rsrc / TmpP_151_Menu.File < prev    next >
Encoding:
Text File  |  1992-04-08  |  5.0 KB  |  277 lines

  1. { %filename% }
  2. { Created %date% %time% by AppMaker }
  3.  
  4. Unit %UnitName%;
  5. Interface
  6.  
  7. Uses
  8.     %if lang = MPW%
  9.         Types,
  10.         Quickdraw,
  11.         Controls,
  12.         Dialogs,
  13.         Events,
  14.         Lists,
  15.         Menus,
  16.         TextEdit,
  17.         Desk,
  18.         Packages,
  19.         ToolUtils,
  20.  
  21.     %end if%
  22.     %for each menuItem gen usesDialog%
  23.  
  24.     Globals,
  25.     ResourceDefs,
  26.     %appName%Data,
  27.     Dispatcher,
  28.     Miscellany;
  29.  
  30. {----------}
  31. Procedure Init%MenuName%M;
  32. Function  OkToOpen    (fType:            OSType): boolean;
  33. Procedure OpenDoc     (fileName:        Str255;
  34.                      vRefNum:        integer);
  35. Procedure OpenApp;
  36. Procedure DoClose;
  37. Procedure DoQuit;
  38. Procedure Do%MenuName%     (itemNr:    integer);
  39.  
  40. {----------}
  41. Implementation
  42.  
  43. %if lang = MPW%
  44.     {$D+}
  45.     {$R+}
  46.     {$OV+}
  47.     {$S %unitname%}
  48.  
  49. %end if%
  50. const
  51.     dialogTop        = 75;
  52.     dialogLeft        = 85;
  53.  
  54. var
  55.     numOpenTypes:    integer;
  56.     openTypeList:    SFTypeList;
  57.  
  58. {----------}
  59. Procedure Init%MenuName%M;
  60. Begin
  61.     numOpenTypes := 1;
  62.     openTypeList [0] := kFileType;
  63. End; {Init%MenuName%M}
  64.  
  65. {----------}
  66. Function OkToOpen    (fType:        OSType): boolean;
  67. var
  68.     i:                integer;
  69.     status:            (searching, found, notFound);
  70. Begin
  71.     i := 0;
  72.     status := searching;
  73.     while status = searching do begin
  74.         if i >= numOpenTypes then begin
  75.             status := notFound;
  76.         end else begin
  77.             if fType = openTypeList [i] then begin
  78.                 status := found;
  79.             end else begin
  80.                 i := i + 1;
  81.             end;
  82.         end;
  83.     end; {while}
  84.     OkToOpen := (status = found);
  85. End; {OkToOpen}
  86.  
  87. {----------}
  88. Procedure DoNew;
  89. Begin
  90.     OpenWindows ('', 0, 0);
  91.     InitAppData;
  92. End; {DoNew}
  93.  
  94. {----------}
  95. Procedure OpenDoc    (fileName:        Str255;
  96.                      vRefNum:        integer);
  97. const
  98.     StationeryFlag    = $0800;    {This *should* be defined in an Apple interface file}
  99.  
  100. var
  101.     isStationery:    boolean;
  102.     finderInfo:        FInfo;
  103.     fRefNum:        integer;
  104. Begin
  105.     isStationery := false;
  106.     if GetFInfo (fileName, vRefNum, finderInfo) = noErr then begin
  107.         if BAnd (finderInfo.fdFlags, StationeryFlag) <> 0 then begin
  108.             isStationery := true;
  109.         end;
  110.     end;
  111.     if OpenAppFile (vRefNum, fileName, fRefNum) then begin
  112.         if isStationery then begin
  113.             OpenWindows ('', 0, 0);
  114.             ReadAppFile (fRefNum);
  115.             CloseAppFile (fRefNum);
  116.         end else begin
  117.             OpenWindows (fileName, vRefNum, fRefNum);
  118.             ReadAppFile (fRefNum);
  119.         end;
  120.     end;    
  121. End; {OpenDoc}
  122.  
  123. {----------}
  124. Procedure DoOpen;
  125. var
  126.     dialogOrigin:    Point;
  127.     sfInfo:            SFReply;
  128. Begin
  129.     SetPt (dialogOrigin, dialogLeft, dialogTop);
  130.     SFGetFile (dialogOrigin, '', nil, numOpenTypes, openTypeList, nil, sfInfo);
  131.     with sfInfo do begin
  132.         if good then begin
  133.             OpenDoc (fName, vRefNum);
  134.         end;
  135.     end;
  136. End; {DoOpen}
  137.  
  138. {----------}
  139. Procedure OpenApp;
  140. Begin
  141.     DoNew;
  142. End; {OpenApp}
  143.  
  144. {----------}
  145. Procedure DoSaveAs;
  146. var
  147.     sfInfo:            SFReply;
  148.     fRefNum:        integer;
  149.     ok:                boolean;
  150.     prompt:            StringHandle;
  151.     suggestion:        Str255;
  152. Begin
  153.     prompt := GetString (SaveAsPromptID);
  154.     suggestion := '';
  155.  
  156.     with sfInfo do begin
  157.         if CreateFile (sfInfo, prompt^^, suggestion, kSignature, kFileType)
  158.         then begin
  159.             CloseAppFile (cur^.fileNum);
  160.             if OpenAppFile (vRefNum, fName, fRefNum) then begin
  161.                 SetWTitle (curWindow, fName);
  162.                 cur^.fileNum := fRefNum;
  163.                 cur^.volNum := vRefNum;
  164.                 WriteAppFile (cur^.fileNum);
  165.                 cur^.dirty := false;
  166.             end else begin {should never happen}
  167.                 SetWTitle (curWindow, '???');
  168.                 cur^.fileNum := 0;
  169.                 cur^.volNum := 0;
  170.             end;
  171.         end;
  172.     end; {with}
  173. End; {DoSaveAs}
  174.  
  175. {----------}
  176. Procedure DoSave;
  177. Begin
  178.     if cur^.fileNum = 0 then begin
  179.         DoSaveAs;
  180.     end else begin
  181.         WriteAppFile (cur^.fileNum);
  182.         cur^.dirty := false;
  183.     end;
  184. End; {DoSave}
  185.  
  186. {----------}
  187. Procedure CloseAppWindow;
  188. const
  189.     saveItem        = 1;
  190.     cancelItem      = 2;
  191.     discardItem     = 3;
  192.     
  193. var
  194.     curTitle:        Str255;
  195.     itemNum:        integer;
  196.     ok:                boolean;
  197. Begin
  198.     ok := true;
  199.     SetInfo (FrontWindow);
  200.     if cur^.dirty then begin
  201.         GetWTitle (curWindow, curTitle);
  202.         ParamText (curTitle, '', '', '');
  203.         InitCursor;
  204.         itemNum := Alert (SaveID, nil);
  205.         case itemNum of
  206.             saveItem: begin
  207.                     DoSave;
  208.                     ok := not errorFlag;
  209.                 end;
  210.             discardItem:
  211.                    {Do nothing};
  212.             cancelItem: begin
  213.                     errorFlag := true;
  214.                     ok := false;
  215.                 end;
  216.         end; {case}
  217.     end;
  218.     if ok then begin
  219.         DisposeAppData;
  220.         if ord (cur^.windowKind) = 1 then begin {1st or only window in set}
  221.             CloseAppFile (cur^.fileNum);
  222.         end;
  223.         CloseCurWindow;
  224.     end;
  225. End; {CloseAppWindow}
  226.  
  227. {----------}
  228. Procedure DoClose;
  229. var
  230.     frontPeek:        WindowPeek;
  231. Begin
  232.     errorFlag := false;
  233.  
  234.     frontPeek := WindowPeek (FrontWindow);
  235.     if frontPeek^.windowKind < 0 then begin
  236.         CloseDeskAcc (frontPeek^.windowKind);
  237.     end else if frontPeek^.windowKind = dialogKind then begin
  238.         CloseModelessDialog (FrontWindow);
  239.     end else begin
  240.         CloseAppWindow;
  241.     end;
  242. End; {DoClose}
  243.  
  244. {----------}
  245. Procedure DoQuit;
  246. var
  247.     quitting:        boolean;                             
  248. Begin
  249.     quitting := true;
  250.     while quitting and (FrontWindow <> nil) do begin
  251.         SystemTask;
  252.         DoClose;
  253.         if errorFlag then begin
  254.             quitting := false;
  255.         end;
  256.     end; {while}
  257.     
  258.     if quitting then begin
  259.         quittingTime := true;
  260.     end;
  261. End; {DoQuit}
  262.  
  263. %for each menuitem gen doItem%
  264. {----------}
  265. Procedure Do%MenuName%    (itemNr:    integer);
  266. Begin
  267.     errorFlag := false;
  268.  
  269.     case itemNr of
  270.         0:    ;
  271.         %for each menuitem gen handleitem%
  272.  
  273.     end; {case}
  274. End; {Do%MenuName%}
  275.  
  276. End. {%UnitName%}
  277.